home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 52 / Amiga Format AFCD52 (Issue 136, May 2000).iso / -serious- / workbench / directoryopus4 / dopus4_src / library / language.c < prev    next >
C/C++ Source or Header  |  2000-03-11  |  5KB  |  143 lines

  1. /*
  2.  
  3. Directory Opus 4
  4. Original GPL release version 4.12
  5. Copyright 1993-2000 Jonathan Potter
  6.  
  7. This program is free software; you can redistribute it and/or
  8. modify it under the terms of the GNU General Public License
  9. as published by the Free Software Foundation; either version 2
  10. of the License, or (at your option) any later version.
  11.  
  12. This program is distributed in the hope that it will be useful,
  13. but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15. GNU General Public License for more details.
  16.  
  17. You should have received a copy of the GNU General Public License
  18. along with this program; if not, write to the Free Software
  19. Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
  20.  
  21. All users of Directory Opus 4 (including versions distributed
  22. under the GPL) are entitled to upgrade to the latest version of
  23. Directory Opus version 5 at a reduced price. Please see
  24. http://www.gpsoft.com.au for more information.
  25.  
  26. The release of Directory Opus 4 under the GPL in NO WAY affects
  27. the existing commercial status of Directory Opus 5.
  28.  
  29. */
  30.  
  31. #include "dopuslib.h"
  32. #include <proto/powerpacker.h>
  33.  
  34. typedef struct {
  35.     ULONG ckID;
  36.     ULONG ckSize;
  37. } ChunkHeader;
  38.  
  39. __saveds DoReadStringFile(register struct StringData *stringdata __asm("a0"),
  40.     register char *filename __asm("a1"))
  41. {
  42.     int a,size,*ptr;
  43.     StringHeader *header;
  44.     String *string;
  45.     char *cptr;
  46.     struct DefaultString *defstr;
  47.     struct Library *PPBase;
  48.     int file,test[3];
  49.     struct Process *myproc;
  50.     APTR wsave;
  51.  
  52.     myproc=(struct Process *)FindTask(NULL);
  53.     wsave=myproc->pr_WindowPtr;
  54.  
  55.     if (!stringdata) return(0);
  56.     if (!stringdata->string_table) {
  57.         if (!(stringdata->string_table=AllocMem(stringdata->string_count*4,MEMF_CLEAR)))
  58.             return(0);
  59.     }
  60.  
  61.     if (stringdata->string_buffer) {
  62.         FreeMem(stringdata->string_buffer,stringdata->string_size);
  63.         stringdata->string_buffer=NULL;
  64.     }
  65.  
  66.     defstr=stringdata->default_table;
  67.  
  68.     for (a=0;a<stringdata->string_count;a++) {
  69.         if (!defstr[a].string) break;
  70.         stringdata->string_table[defstr[a].string_id]=defstr[a].string;
  71.     }
  72.  
  73.     myproc->pr_WindowPtr=(APTR)-1;
  74.     if (filename && (file=Open(filename,MODE_OLDFILE))) {
  75.         Read(file,(char *)test,12);
  76.         if (test[0]=='PX20' || test[0]=='PP11' || test[0]=='PP20') {
  77.             Close(file);
  78.             if ((PPBase=OpenLibrary("powerpacker.library",0))) {
  79.                 ppLoadData(filename,
  80.                     DECR_NONE,
  81.                     MEMF_CLEAR,
  82.                     &stringdata->string_buffer,
  83.                     &stringdata->string_size,
  84.                     NULL);
  85.                 CloseLibrary(PPBase);
  86.             }
  87.         }
  88.         else {
  89.             if (test[0]==ID_FORM && test[2]==ID_OSTR) {
  90.                 Seek(file,0,OFFSET_END);
  91.                 if ((stringdata->string_size=Seek(file,0,OFFSET_BEGINNING))>0 &&
  92.                     (stringdata->string_buffer=AllocMem(stringdata->string_size,0)))
  93.                     Read(file,stringdata->string_buffer,stringdata->string_size);
  94.             }
  95.             Close(file);
  96.         }
  97.     }
  98.     myproc->pr_WindowPtr=wsave;
  99.  
  100.     if (stringdata->string_buffer) {
  101.         ptr=(int *)stringdata->string_buffer;
  102.         header=(StringHeader *)&stringdata->string_buffer[12];
  103.  
  104.         if (ptr[0]!=ID_FORM || ptr[2]!=ID_OSTR ||
  105.             header->header_id!=ID_STHD ||
  106.             header->version<stringdata->min_version) {
  107.             FreeMem(stringdata->string_buffer,stringdata->string_size);
  108.             stringdata->string_buffer=NULL;
  109.         }
  110.         else {
  111.             cptr=(char *)header+sizeof(StringHeader);
  112.  
  113.             for (a=0;a<header->stringcount;a++) {
  114.                 string=(String *)cptr;
  115.                 if (string->chunk_id==ID_STRN) {
  116.                     if (string->string_id>=0 &&
  117.                         string->string_id<stringdata->string_count)
  118.                         stringdata->string_table[string->string_id]=cptr+sizeof(String);
  119.                 }
  120.                 size=string->chunk_size+sizeof(ChunkHeader);
  121.                 if (size%2) ++size;
  122.                 cptr+=size;
  123.                 if (cptr>=(stringdata->string_buffer+stringdata->string_size)) break;
  124.             }
  125.         }
  126.     }
  127.     return(1);
  128. }
  129.  
  130. void __saveds DoFreeStringFile(register struct StringData *stringdata __asm("a0"))
  131. {
  132.     if (stringdata) {
  133.         if (stringdata->string_buffer) {
  134.             FreeMem(stringdata->string_buffer,stringdata->string_size);
  135.             stringdata->string_buffer=NULL;
  136.         }
  137.         if (stringdata->string_table) {
  138.             FreeMem(stringdata->string_table,stringdata->string_count*4);
  139.             stringdata->string_table=NULL;
  140.         }
  141.     }
  142. }
  143.